﻿using Covid.Server.Data;
using Covid.Server.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Covid.Server.Services
{
    public class DepartmentRepository : IDepartmentRepository
    {

        private readonly MyDbContext _context;
        /// <summary>
        /// 通过构造函数注入dbContext
        /// </summary>
        public DepartmentRepository(MyDbContext context) {
            _context = context;
        }


        /// <summary>
        /// 查询全部
        /// </summary>
        /// <returns></returns>
        public async Task<List<Department>> GetAllAsync()
        {
            var all = await _context.Departments.ToListAsync();
            return all;
        }


        /// <summary>
        /// 根据ID查询
        /// </summary>
        /// <param name="departmentId"></param>
        /// <returns></returns>
        public async Task<Department> GetByIdAsync(int departmentId)
        {
            var one = await _context.FindAsync<Department>(departmentId);
            return one;
        }

    }
}
